from pyflink.datastream import StreamExecutionEnvironment, RuntimeExecutionMode, MapFunction, FilterFunction

# 1、创建flink执行环境
env = StreamExecutionEnvironment.get_execution_environment()

# 修改并行度
env.set_parallelism(1)

# 2、读取数据,得到DataStream，相当于RDD  （有界流）
lines_ds = env.read_text_file("G:\LanZhiPeiXun\Flink\data\students.txt")

# 1、lambda表达式
filter_ds = lines_ds.filter(lambda line: line.split(",")[-1] == "文科一班")

# filter_ds.print()

# 2、类和对象方式
class ClazzFilterFunction(FilterFunction):

    def filter(self, line):
        return line.split(",")[-1] == "文科一班"


lines_ds.filter(ClazzFilterFunction()).print()


env.execute()
